
getUserInfo()



//实现退出功能
$('#logOut').on('click', function (e) {
    e.preventDefault()
    var layer = layui.layer
    layer.confirm('确定退出登录?', { icon: 3, title: '提示' }, function (index) {
        //do something
        localStorage.removeItem('token')
        location.href = '/login.html'
        layer.close(index);
    });
})


// 封装函数获取用户、头像基本信息
function getUserInfo() {
    $.ajax({
        type: 'GET',
        url: '/my/userinfo',
        success: function (res) {
            if (res.status !== 0) return layui.layer.msg(res.message)
            var username = res.data.nickname || res.data.username
            $('#welcome').html(`您好: ${username}`)
            if (res.data.user_pic !== null) {
                $('.user-pic').hide()
                $('.layui-nav-img').attr('src', res.data.user_pic)
            } else {
                $('.layui-nav-img').hide()
                var n = res.data.username.slice(0, 1).toUpperCase()
                $('.user-pic').html(n)
            }
        }
    })
}

//显示当前时间
time()
setInterval(time, 1000);
function time() {
    var vWeek, vWeek_s;
    vWeek = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    var date = new Date();
    year = date.getFullYear();
    month = date.getMonth() + 1;
    day = date.getDate();
    hours = date.getHours();
    minutes = date.getMinutes();
    seconds = date.getSeconds();
    vWeek_s = date.getDay();
    document.getElementById("time").innerHTML = year + "-" + Zero(month) + "-" + Zero(day) + "\t" + Zero(hours) + ":" + Zero(minutes) + ":" + Zero(seconds) + "\t" + vWeek[vWeek_s];
};

function Zero(n) {
    return n = n < 10 ? '0' + n : n
}





